package com.gsoe;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.Collections;

public class CodeGeneratorForGDBC {
    public static void main(String[] args) {
        FastAutoGenerator.create(new DataSourceConfig.Builder("jdbc:mysql://192.168.101.129:3306/user", "root", "root"))
            .globalConfig(builder -> {
                builder
                        .author("xiaoma") // 设置作者
                        .outputDir("online-exam-generator\\src\\main\\java\\user"); // 指定输出目录
            })
            .packageConfig(builder -> {
                builder.parent("com.gsoe.auth") // 设置父包名
                        .pathInfo(Collections.singletonMap(OutputFile.mapper, "online-exam-generator\\src\\main\\resources\\user\\mapper")); // 设置mapperXml生成路径
            })
            .strategyConfig(builder -> {
                builder.addInclude("resource") // 设置需要生成的表名
                        .entityBuilder().naming(NamingStrategy.underline_to_camel).enableLombok() // 生成的实体类使用Lombok
                        .controllerBuilder().enableRestStyle() // 生成 @RestController 控制器
                        .mapperBuilder().enableBaseResultMap(); // 启用 BaseResultMap
            })
            .templateEngine(new VelocityTemplateEngine()) // 使用Velocity模板引擎
            .execute();
    }
}

